#pragma once
#ifndef HRESULT_CHECK_AND_RET
#define HRESULT_CHECK_AND_RET(x) {	if (FAILED(x)) 	{ assert(0); return x; }}
#endif

#ifndef HRESULT_CHECK
#define HRESULT_CHECK(x) {	if (FAILED(x)) 	{ assert(0); }}
#endif

#ifndef SAFE_ADDREF
#define SAFE_ADDREF(p)      { if (p) { (p)->AddRef(); } }
#endif

#ifndef SAFE_RELEASE
#define SAFE_RELEASE(p)       { if (p) { (p)->Release();  (p) = NULL; } }
#endif

#ifndef SAFE_DELETE_ARRAY
#define SAFE_DELETE_ARRAY(p)  { if (p) { delete [](p); p = NULL; }}
#endif

#ifndef SAFE_DELETE
#define SAFE_DELETE(p)        { if (p) {delete (p); p = NULL;  }}
#endif

#ifndef SAFE_CVRELEASE
#define SAFE_CVRELEASE(p)     { if (p) { cvRelease((&p)); (p) = NULL; } }
#endif

#ifndef SAFE_CVRELEASE_IMAGE
#define SAFE_CVRELEASE_IMAGE(p)     { if (p) { cvReleaseImage((&p)); (p) = NULL; } }
#endif

#ifndef SAFE_CVRELEASE_IMAGEHEADER
#define SAFE_CVRELEASE_IMAGEHEADER(p)     { if (p) { cvReleaseImageHeader((&p)); (p) = NULL; } }
#endif

#ifndef SAFE_CVRELEASE_MEMSTORAGE
#define SAFE_CVRELEASE_MEMSTORAGE(p)     { if (p) { cvReleaseMemStorage((&p)); (p) = NULL; } }
#endif


#ifndef SAFE_CVRELEASE_HaarClassifierCascade
#define SAFE_CVRELEASE_HaarClassifierCascade(p)     { if (p) { cvReleaseHaarClassifierCascade((&p)); (p) = NULL; } }
#endif